package com.shuyu.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.shuyu.domain.ApprovalProcessDetail;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ApprovalProcessDetailMapper extends BaseMapper<ApprovalProcessDetail> {

    @Select("select * from ( " +
            "select DISTINCT t1.*,case t1.`type` when 1 then t2.name else t3.name end as source_name  from ( " +
            "SELECT DISTINCT t1.* FROM tbl_approval_process_detail t1 left join tbl_approval_process_flow t2 on t1.id=t2.detail_id " +
            "where (t2.user_id=#{userId} or t2.authorization_user_id = #{userId}) and t1.auditing_status !=0 " +
            "UNION ALL " +
            "SELECT DISTINCT t1.* FROM tbl_approval_process_detail t1 left join tbl_approval_process_flow t2 on t1.id=t2.detail_id " +
            "where (t2.user_id=#{userId} or t2.authorization_user_id = #{userId}) and t1.auditing_status=0 " +
            "${sql}" +
            ")t1 " +
            "left join tbl_product t2 on t1.source_id  = t2.id " +
            "left join tbl_activity t3 on t1.source_id = t3.id " +
            "left join sys_user t4 on t1.create_user_id = t4.user_id " +
            "${ew.customSqlSegment}" +
            ")t1")
    List<ApprovalProcessDetail> getList(@Param(Constants.WRAPPER) QueryWrapper wrapper,@Param("sql") String sql,@Param("userId")long userId);
}
